from sqlalchemy import select

from exception.customException import UserNotFoundException,PasswordNotMatchException
from model import Session
from model.admin import Admin,AdminModel

class AdminService:
    @staticmethod
    def login(admin: AdminModel, db_session: Session) -> Admin:
        query = select(Admin).where(Admin.username == admin.username)
        result = db_session.execute(query).scalars().first()
        if not result:
            raise UserNotFoundException("用户不存在")
        if result.password != admin.password:
            raise PasswordNotMatchException("身份验证未通过")
        return result
